<?php

class Zend_View_Helper_IsUserAllowed
{
	function isUserAllowed($arg) 
	{
		$allowed = false;
		
		if (!is_array($arg)) {
			$arg = array($arg);
		}

		// Get the acl from the registry (provided by AuthorizationPlugin)
		$acl = Zend_Registry::getInstance()->get("acl");
		
		// Arguments module / controller / action
		if (isset($arg['controller']) && isset($arg['action'])) {
			$resource = (isset($arg['module']) ? $arg['module'] : "default") . "/" . $arg['controller'];
			$privledge = $arg['action'];
	        try {
	    		$allowed = $acl->isAllowed("user", $resource, $privledge);
	        } catch (Zend_Acl_Exception $e) {
	        	$allowed = false;
	        }
		} 
     	
     	return $allowed;
	}
}